<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>Q Light Controller Plus - RGBScript Development Tool</title>
<style>
  .readonly {
    background-color: lightgrey;
    border: solid 0px;
  }
  body {
    background: #373737;
    color: #f9f8f0;
    font-family: Arial;
    min-height: calc(100vh - 16px); /* Subtract padding to prevent vertical scrollbar */
    padding: 8px;
    margin: 0;
  }
  h2 {
    background: #aaa;
    color: #333;
    padding: 10px;
  }
  .box {
    padding: 10px;
    display: inline-block;
    vertical-align: top;
    min-width: 200px;
  }
  :nth-child(1 of .box) {
    padding-left: 0;
  }
  :nth-last-child(1 of .box) {
    padding-right: 0;
  }
  input[type=button] {
    background-color: #7497b6;
    border: none;
    color: white;
    padding: 5px 10px;
    text-decoration: none;
    margin: 4px 2px;
    font-size: 16px;
    cursor: pointer;
  }
  input[type=button]:hover {
    background-color: #8db8dd;
  }
  table:not(#map), table input[type=text], table input[type=number], table input[type=color], table select {
    width: 100%;
    min-width: 75px;
    box-sizing: border-box;
  }
  #dropContainer {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: 100vw;
    color: #000;
    background: none;
    font-size: 2em;
    pointer-events: none;
    justify-content: center;
    align-items: center;
  }
  #dropContainer.dragging {
    display: flex;
    background-color: rgba(255,255,255,0.7);
  }
</style>
<script type="text/javascript" src="devtool/devtool.js"></script>
</head>
<body onLoad="devtool.onLoad()">

<div id="dropContainer">
   &#8609;&#xFE0E; Drop your RGB script here to load it &#8609;&#xFE0E;
</div>

<h1>Q Light Controller Plus - RGB Script Development Tool</h1>

<div>
<h2>Instructions</h2>
<p>
To use this tool, you must first set the filename of the script you intend to test/debug
(including the .js extension) in the 'filename' field. Then hit 'enter' to load it.
Alternatively, you can use the 'browse' button to select the file from your local file system.
A third option is to drag and drop the file directly into this page.
</p>
<p>
To make your algorithm object accessible to this tool, you must create a global variable
within your algorithm file called <b>testAlgo</b>, which then actually contains your algorithm
object i.e. the object that provides rgbMap() and rgbMapStepCount() functions. Now you're ready to load
this file with your browser and see your first results.
</p>

<p>
If you see what you expect to see in the <b>Algorithm Properties</b> section below,
you'll know your script has been evaluated successfully. Next, put some values to the
<b>Width</b> and <b>Height</b> boxes in the <b>Grid Size</b> section and see if your
script calculates the <b>rgbMapStepCount(width, height)</b> result correctly.
If everything is OK, you should already see your RGB script running through frames.
To inspect individual frames, stop the script and hit the previous and next buttons.
</p>

<b>
For troubleshooting purposes, I would suggest using some good JavaScript development
tools for your browser. Mozilla FireFox has a built-in Web Console behind <i>Tools -> Web
Developer</i> which is very useful in hunting errors within the JavaScript code.
Google Chrome has one as well, that you can access with F12 or with <i>More Tools -> Developer Tools (Ctrl+Shift+I)</i>
</b>
</div>

<div class="box">
<h2>Load script</h2>
<form>
<table id="definitions">
 <tr>
  <td><label for="filename">Enter a filename</label></td>
  <td><input type="text" size="12" id="filename" placeholder="Enter filename here." onChange="devtool.onFilenameUpdated(this.value)"/></td>
 </tr>
 <tr>
  <td><label for="filebrowse">Or browse</label></td>
  <td><input type="file" size="12" id="filebrowse" onChange="devtool.onFileBrowsed(event)"/></td>
 </tr>
</table>
</form>

<h2>Algorithm specification</h2>
<form>
<table id="definitions">
 <tr>
  <td><label for="apiversion">apiVersion</label></td>
  <td><input type="text" readonly="readonly" class="readonly" size="3" id="apiversion"/></td>
 </tr>
 <tr>
  <td><label for="name">name</label></td>
  <td><input type="text" readonly="readonly" class="readonly" id="name"/></td>
 </tr>
 <tr>
  <td><label for="author">author</label></td>
  <td><input type="text" readonly="readonly" class="readonly" id="author"/></td>
 </tr>
 <tr>
  <td><label for="acceptColors">acceptColors</label></td>
  <td><input type="text" readonly="readonly" class="readonly" id="acceptColors"/></td>
 </tr>
</table>
</form>

<h2>Grid size</h2>
<form>
<table>
 <tr>
  <td><label for="gridwidth">Width</label></td>
  <td><input type="number" min="1" id="gridwidth" value="15" size="4" required onChange="devtool.onGridSizeUpdated()"/></td>
 </tr>
 <tr>
  <td><label for="gridheight">Height</label></td>
  <td><input type="number" min="1" id="gridheight" value="15" size="4" required onChange="devtool.onGridSizeUpdated()"/></td>
 </tr>
 <tr>
  <td><label for="gridsize">Size</label></td>
  <td><input type="number" min="1" max="20" id="gridsize" value="20" size="4" required onChange="devtool.onGridSizeUpdated()"/></td>
 </tr>
</table>
</form>

</div>

<div class="box">
<form id="pixelColorChooser">
<h2>Pixel colors</h2>
<table id="colorChooserTable">
</table>
</form>

<h2>Algorithm properties</h2>
<form>
<table id="properties">
</table>
</form>

<h2>Algorithm functions</h2>
<form>
<table>
 <tr>
  <td><label for="stepCount">rgbMapStepCount(width, height)</label></td>
  <td><input type="text" readonly="readonly" class="readonly" size="3" id="stepCount"/></td>
 </tr>
 <tr>
  <td><label for="currentStep">rgbMap(width, height, rgb, <b>step</b>)</label></td>
  <td>
   <input type="number" min="0" id="currentStep" onChange="devtool.writeCurrentStep()"/>
  </td>
 </tr>
 <tr>
  <td colspan="2">
    <input type="button" value="&#x23EA;&#xFE0E; Previous" onClick="devtool.previousStep()"/>
    <input type="button" value="&#x23E9;&#xFE0E; Next" onClick="devtool.nextStep()"/>
    <input type="button" value="&#x23F5;&#xFE0E; Start" onClick="devtool.startTest(1)"/>
    <input type="button" value="&#x23F9;&#xFE0E; Stop" onClick="devtool.stopTest()"/>
    <input type="button" value="&#x23F4;&#xFE0E; Start reversed" onClick="devtool.startTest(-1)"/>
  </td>
 </tr>
 <tr>
  <td><label for="alternate">Alternate</label></td>
  <td>
   <input type="checkbox" id="alternate" onChange="devtool.onAlternateChanged()"/>
  </td>
 </tr>
 <tr>
  <td><label for="speed">Speed (ms)</label></td>
  <td>
   <input type="number" min="1" id="speed" value="500" size="4" onChange="devtool.onSpeedChanged()"/>
  </td>
 </tr>
</table>
</form>

</div>

<div class="box">
<h2>Preview</h2>
<table id="map">
</table>
</div>

<hr/>
This file is licensed under the Apache 2.0 license. Copyright &copy; Heikki Junnila, Massimo Callegari, APIv2 & APIv3 integration: Hans-Jürgen Tappe.

</body>
</html>
